package com.tjmc.company.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.company.api.entity.JobCategoryEntity;
import com.tjmc.company.service.JobCategoryService;
import com.tjmc.recruit.common.core.util.R;
import com.tjmc.recruit.common.log.annotation.SysLog;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;

import com.tjmc.recruit.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import com.tjmc.recruit.common.security.annotation.HasPermission;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 职位分类表
 *
 * @author recruit
 * @date 2024-11-29 15:24:34
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/jobCategory" )
@Tag(description = "jobCategory" , name = "职位分类表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class JobCategoryController {

    private final JobCategoryService jobCategoryService;

    /**
     * 行业及岗位分类树结构
     * @param level 查看层级
     * @return R  对象列表
     */
    @Operation(summary = "行业及岗位分类树结构" , description = "行业及岗位分类树结构" )
    @SysLog("行业及岗位分类树结构" )
    @GetMapping("/tree" )
    @Inner(value = false)
    public R getTree(@ParameterObject Integer level) {
        return R.ok(jobCategoryService.treeCategories(level));
    }


    /**
     * 新增职位分类表
     * @param jobCategory 职位分类表
     * @return R
     */
    @Operation(summary = "新增职位分类表" , description = "新增职位分类表" )
    @SysLog("新增职位分类表" )
    @PostMapping
    public R save(@RequestBody JobCategoryEntity jobCategory) {
        return R.ok(jobCategoryService.save(jobCategory));
    }

    /**
     * 修改职位分类表
     * @param jobCategory 职位分类表
     * @return R
     */
    @Operation(summary = "修改职位分类表" , description = "修改职位分类表" )
    @SysLog("修改职位分类表" )
    @PutMapping
    public R updateById(@RequestBody JobCategoryEntity jobCategory) {
        return R.ok(jobCategoryService.updateById(jobCategory));
    }

    /**
     * 通过id删除职位分类表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除职位分类表" , description = "通过id删除职位分类表" )
    @SysLog("通过id删除职位分类表" )
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(jobCategoryService.removeBatchByIds(CollUtil.toList(ids)));
    }
}
